<template>
	<nav-header :title="'我的活动(' + data.pageTotal + ')'">
		<view class="px-4 border-b-ee-solid bg-white z-20">
			<u-tabs :current="current" :list="tabList" :activeStyle="{color: '#2d58cb',transform: 'scale(1.05)'}"
				:inactiveStyle="{ color: '#999999',transform: 'scale(1)'}" lineWidth="34"
				itemStyle="width: 50%;height: 44px;align: center;padding-left: 0px; padding-right: 0px;z-index: 20"
				lineColor="#2d58cb" @change="({index})=>{current = index;reloadData()}"></u-tabs>
		</view>
		<my-page ref="mypage" v-model="dataList" :height="system.screenHeight - system.statusBarHeight - 89" :contentClass="['pt-4', 'px-4']" @load-data="loadData">
			<template slot="content">
				<view v-for="(item,index) in dataList" :key="index" class="bg-white mb-4 px-4 py-5 rounded-lg shadow-lg"
					@click="goNav(item)">
					<view class="text-black-33 font-bold mb-2 text-lg" v-text="item.title"></view>
					<view class="flex text-gray-66">
						<text>活动时间：</text>
						<text v-text="$util.getFormatDate(item.startTime) + ' ~ ' + $util.getFormatDate(item.endTime)"></text>
					</view>
					<view class="flex text-gray-66">
						<text>活动地址：</text>
						<text v-text="item.address"></text>
					</view>
				</view>
			</template>
		</my-page>
	</nav-header>
</template>

<script>
	import {mapState} from 'vuex'
	import MyPage from '@/components/my_page.vue'
	import NavHeader from '@/components/nav_header.vue'
	import * as activityApi from '@/interface/junchuang/activity.js'
	import MescrollPageMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-page.js"
	export default {
		mixins: [MescrollPageMixin],
		components: {
			NavHeader,MyPage
		},
		data() {
			return {
				current: 0,
				tabList: [
					{name: '园区活动'},
					{name: '其他活动'}
				],
				dataList: [],
				data: {pageTotal: 0},
			}
		},
		computed: {
			...mapState({
				system: state => state.system
			})
		},
		onShow() {
      this.$util.openShare();
		},
		onPullDownRefresh () {
			this.$refs['mypage'].dataReload()
			uni.stopPullDownRefresh()
		},
		methods: {
			loadData(page, success, error){
				const v = this
				Object.assign(v.data, page, {
					type: v.current + 1
				})
				activityApi.getMineActivityPage(v.data).then(res=>{
					v.data.pageTotal = res.data.total || 0
					success(res)
				}).catch(error)
			},
			goNav (item) {
				let url = this.current == 0? '/pages_home/junchuang_detail?id=':'/pages_home/junchuang_detail?id='
				this.$util.myNavigateTo(url + item.id)
			},
			reloadData () {
				this.$refs['mypage'].dataReload()
			}
		}
	}
</script>

<style>
	page{
		background-color: #f7f7f7;
	}
</style>
